<?php
/**
 * 晋商
 *
 * @author lwb
 */

namespace app\wechat\controller;

class JinshangFund extends Common {

    //开通账户
    public function openAccount($params) {
        //用户信息
        $userinfo = $this->getWS('ucenter', 'users@userInfo', ['u_code' => $this->uid]);
        
        //组装输入参数
        $data = [
            'ub_card_no' => $userinfo['result']['ub_card_no'],
            'u_true_name' => $userinfo['result']['u_true_name'],
            'u_ident_no' => $userinfo['result']['u_ident_no'],
            'u_name' => $userinfo['result']['ub_phone'],
        ];
        
        //电子账户信息
        $return = $this->getWS('channel', 'jinshangfund@openAccount', $data);
        if($return['status'] != '2000'){
            $result = ['code' => 5000, 'msg' => '开通电子账户失败'];
            return $this->parse_data($result);
        }

        //保存电子账户
        $return = $this->getWS('ucenter', 'fund@saveAccount', ['u_code' => $this->uid, 'fundName' => 'jinshang', 'accountno' => $return['result']['accountno']]);
        if($return['status'] != '2000'){
            $result = ['code' => 5000, 'msg' => '开通电子账户失败'];
            return $this->parse_data($result);
        }
        
        $result = ['data' => ['isJump' => false]];
        
        return $this->parse_data($result);
    }
    
    /*
     * 更换银行卡
     */
    public function updateBank(){
        $bankInfo = request()->param();
        $data = [
            'service' => 'CF201016',
            'applseq' => $bankInfo['applseq'],
            'applacnams22' => $bankInfo['bank_name'],
            'applacnamr2' => $bankInfo['card_no'],
            'tel2' => $bankInfo['bank_phone'],
        ];
        $return = $this->getWS('channel', 'jinshangfund@jinshangInterface', $data);
        if($return['status'] != '2000'){
            $result = ['code' => 5000, 'msg' => '变更失败'];
            return $this->parse_data($result);
        }
        $this->getWS('ucenter', 'bank@updateBank', [
            'applseq' => $bankInfo['applseq'],
            'bank_name' => $bankInfo['bank_name'],
            'bank_code' => $bankInfo['card_no'],
            'bank_phone' => $bankInfo['bank_phone'],
        ]);
        
        return $this->parse_data($result);
    }
    
}
